package com.example.test001.web;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;


import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class BaseController {


    /**
     * 字符串转换成日期
     *
     * @param binder
     */

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
            @Override
            public void setAsText(String text) throws IllegalArgumentException {
                try {
                    setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(text));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });


    }


    @GetMapping("error/404")
    public String page404() {
        return "error/404";

    }


    @GetMapping("error/500")
    public String page500() {
        return "error/500";
    }


}


